<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/main.css" />
    <link rel="stylesheet" type="text/css" href="../../css/demo/job.css" />
</head>
<body>
  <div id="header">
    <div id="back"></div>
      <h3>我的帖子</h3>
  </div>
  <div id="all" class="myArticle">
  <!-- <div class="search">
    <input type="text" name="" placeholder="请输入您要搜索的关键字">
    <span>搜索</span>
  </div> -->
  <div class="bt">
  </div>

  <!-- <div class="circle" onclick="openPage('chatContacts','project/chatContacts.html')" tapmode>
    <img src="../image/say.png" class="book_img">
  </div> -->
  </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.js"></script>
<script type="text/javascript">
apiready=function(){
var aid=$api.getStorage("aid");
var items=[];
var msgUrl='/api/public-msgs?sort=createTime,desc&aid='+aid+'&type=0&page=0&size=10';
var NVNavigationBar = api.require('NVNavigationBar');
var count=0;
init();
function getSort(){
    var Url='/type/types/student/1';
    var functionRet=function(ret1){
      var items=[{
            title: "全部",
            bg: 'rgba(86, 119, 252,0.8)',
            alpha: 0.8,
            bgSelected: 'rgba(86, 119, 252,0.8)',
          }];
      for (var i = 0; i < ret1.data.length; i++) {
        items.push({
          title: ret1.data[i].name,
          bg: 'rgba(86, 119, 252,0.8)',
          alpha: 0.8,
          bgSelected: 'rgba(86, 119, 252,0.8)',
        });
      }
      NVNavigationBar.open({
          rect: {
               x: 0,
               y: 60,
               w: api.frameWidth,
               h: 44
          },
         styles: {
               orientation: 'horizontal',
               bg: '#EEEEEE',
               bgAlpha: 1,
               font: {
               size: 14,
               sizeSelected: 16,
               color: '#ccccff',
               colorSelected: '#FFFFFF',
               alpha: 1
               },
               itemSize: {
                   w: api.frameWidth/4,
                   h: 45
               }
         },
          items:items,
             selectedIndex: 0,
             fixedOn: api.frameName,
             fixed:true,
             id: 'first'
      }, function(ret, err) {
          if(ret.eventType=="click"){
            //msgUrl='/api/public-msgs?type='+ret.index+'&page=0&size=10';
            $(".bt").empty();
            getContent(ret.index,count,10);
            selectType=ret.index;
          }
      });
    }
    var functionErr=function(err1){
      return false;
    }
    getNew(Url,functionRet,functionErr);
}
//--------------------------------------------------------
function init(){
  //alert(aid)
  //getContent(msgUrl);
  getSort();
  getContent(0,count,10);
}
//--------------------------------------------------------

//获取自己发表的文章
// function getContent(msgUrl){
//   var functionRet=function(ret1){
//       if(ret1.length){
//         for (var i = 0; i < ret1.length; i++) {
//            var imageSrc=ret1[i].imageList.toString().split(',')
//               $(".bt").append('<div class="showModule" showModule-id='+ret1[i].id+'><div class="headerImage"><img src='+ret1[i].userHeaderImageUrl+'><span class="username">'+ret1[i].userName+'</span><span class="delete">删除</span></div><h3 class="showModule_t">'+ret1[i].title+'</h3><div class="Image"></div><div class="article">'+ret1[i].content+'</div><div><img src='+"http://"+imageSrc[0].replace(/["'"]/g,"")+'></div></div>');
//         }
//       }
//       //将点击的文章的id传给文章详情页面
//       $(".at").on("click",function(){
//           api.openWin({
//               name: 'article',
//               url: 'article.html',
//               pageParam: {
//                   id:ret1[$(this).parent().index()].id  //文章id
//               }
//           });
//       });
//       $(".delete").on("click",function(){
//           deleteArticle(ret1[$(this).parent().index()].id);
//       });
//     }
//     var functionErr=function(err1){
//       return false;
//     }
//     get(msgUrl,functionRet,functionErr);
// }
function getContent(type,page,size){
  if(type==0){
    msgUrl='/api/public-msgs?sort=createTime,desc&aid='+aid+'&page='+page+'&size='+size;
  }else{
    type--;
    msgUrl='/api/public-msgs?sort=createTime,desc&aid='+aid+'&type='+type+'&page='+page+'&size='+size;
  }
  var functionRet=function(ret1){
      if(ret1.length){
        for (var i = 0; i < ret1.length; i++) {
          if(ret1[i].imageList!=""){
            var imageSrc=ret1[i].imageList.toString().split(',')
              $(".bt").append('<div class="showModule"><div class="headerImage"><img src='+ret1[i].userHeaderImageUrl+'><span class="username">'+ret1[i].userName+'</span><span class="delete" style="color:red;" delete-id='+ret1[i].id+'>删除</span></div><div class="At" At-id='+ret1[i].id+'><h3 class="showModule_t">'+ret1[i].title+'</h3><span class="createTime">发表时间:'+ret1[i].createTime+'</span><div class="Image"></div><div class="article">'+ret1[i].content+'</div><div><img src='+"http://"+imageSrc[0].replace(/["'"]/g,"")+'></div></div></div>');
          }
        }
      }
      /*
      上面代码是按依次显示出来
      下面是点击了上面排列的第几个，就获取那个的id跟内容传给下个页面
      */
      $(".delete").on("click",function(){
           deleteArticle($(this).attr('delete-id'));
       });
      // $(".bt").on("click",function(){
      //     api.openWin({
      //         name: 'article',
      //         url: 'article.html',
      //         pageParam: {
      //             id:ret1[$(this).parent().index()].id  //文章id
      //         }
      //     });
      // });
      $(".At").on("click",function(){
          api.openWin({
              name: 'article',
              url: './article.html',
              pageParam: {
                  id:$(this).attr('At-id')
              }
          });
      });
    }
    var functionErr=function(err1){
      return false;
    }
    getU(msgUrl,functionRet,functionErr);
}
//--------------------------------------------------------
//删除文章
function deleteArticle(id){
    var url="/api/public-msgs/"+id;
    var data="";
    var functionRet=function(ret1){
      //alert("删除成功！");
    }
    var functionErr=function(err1){
      if(err1.statusCode==200){
        alert("文章删除成功！");
        var jsfun = 'reloadHtml();';
        api.execScript({
            name: 'root',
            frameName: 'frame2',
            script: jsfun
        });
        window.location.reload();
      }
    }
    deleteData(url,data,functionRet,functionErr);
}

}
$(function(){
  back();
})
</script>
<script type="text/javascript" src="../../script/main.js"></script>
</html>
